﻿using System.Xml.Linq;
using Maple.Weixin.MP.Helpers;

namespace Maple.Weixin.MP.Entities.Messages
{
    public sealed class ResponseMessageImage : ResponseMessageBase
    {
        internal ResponseMessageImage(string mediaId, bool encrypt)
            : base(encrypt) {
            this.mediaId = mediaId;
        }

        internal ResponseMessageImage(string mediaId) : this(mediaId, false) {}

        public override ResponseMessageType MessageType
        {
            get { return ResponseMessageType.Image; }
        }

        private string mediaId;

        public string MediaId {
            get { return mediaId ?? ""; }
            private set { mediaId = value; }
        }

        public override XDocument ToXDocumentBase()
        {
            var document = new XDocument(
                new XElement("xml",
                             new XElement("ToUserName", new XCData(ToUserName)),
                             new XElement("FromUserName", new XCData(FromUserName)),
                             new XElement("CreateTime", WeixinHelper.GetWeixinDateTime(CreateTime)),
                             new XElement("MsgType", new XCData(MessageType.ToString().ToLower())),
                             new XElement("Image", new XElement("MediaId", new XCData(MediaId)))
                    ));
            return document;
        }
    }
}
